<template>
	<!-- 商家端-首页 -->
	<view class="storeHome-main">
		<view class="storeHome-content">
			<!-- 商家信息 -->
			<view class="storeInfo">
				<view class="storeInfo-image">
					<image :src="imageUrls(storeInfo.image)" style="width: 100rpx; height: 100rpx; border-radius: 50%"></image>
				</view>
				<view class="storeInfos">
					<view class="storeInfo-title">
						{{ storeInfo.name || '暂无名称' }}
					</view>
					<view class="storeInfo-zh">
						<text style="font-size: 24rpx">
							{{ storeInfo.address || '暂无地址' }}
						</text>
						<uni-tag :text="userInfo.user_id == storeInfo.user_id ? '店主':'店员'" type="warning" class="tags" size="mini" v-if="storeType != 2"/>
						<uni-tag text="创客" type="warning" class="tags" size="mini" v-else/>
					</view>
				</view>
			</view>

			<!-- 商品销售提现 -->
			<view class="store-shopWithdraw" v-if="balanceInfo">
				<view class="store-shopWithdraw-header">商品销售可提现(元)</view>
				<view class="store-shopWithdraw-midden">
					<view class="money" >
						<text>￥{{ formatAmounts(balanceInfo.balance) }}</text>
					</view>
					<view class="btn" @click="gotoPath('/pages/storeSide/ydWithdraw/ydWithdraw')">
						<button type="primary" size="mini" class="btnSty">提现</button>
					</view>
				</view>
				<view class="store-shopWithdraw-footer">
					<view class="footerItem">
						<view class="num">
							{{ formatAmounts(balanceInfo.today_sale) }}
						</view>
						<view class="title">今日销售</view>
					</view>
					<view class="footerItem borders">
						<view class="num">
							{{ formatAmounts(balanceInfo.wait_sale) }}
						</view>
						<view class="title">销售待结算</view>
					</view>
					<view class="footerItem">
						<view class="num">
							{{ formatAmounts(balanceInfo.total_sale) }}
						</view>
						<view class="title">累计销售收入</view>
					</view>
				</view>
			</view>

			<!-- 管理 -->
			<view class="store-option" v-if="storeType == '0' || storeType == '1'">
				<u-row justify="space-between" gutter="8">
					<u-col span="4">
						<view class="option-item" style="background-color: rgb(224 240 254)" @click="gotoPath('/pages/storeSide/ownerManagement/ownerManagement')">
							<view class="title" style="color: rgb(75, 138, 211)">店主管理</view>
							<view class="des">店主管理</view>
						</view>
					</u-col>
					<u-col span="4">
						<view class="option-item" style="background-color: rgb(204 249 232)" @click="gotoPath('/pages/storeSide/makerManagement/makerManagement')">
							<view class="title" style="color: rgb(24, 165, 157)">创客管理</view>
							<view class="des">创客管理</view>
						</view>
					</u-col>
					<u-col span="4">
						<view class="option-item" style="background-color: rgb(239 236 255)" @click="gotoPath('/pages/storeSide/membershipManagement/membershipManagement')">
							<view class="title" style="color: rgb(103, 85, 198)">会员管理</view>
							<view class="des">会员管理</view>
						</view>
					</u-col>
				</u-row>
			</view>

			<!-- 常用工具 -->
			<view class="store-tools" style="margin-top: 30rpx">
				<view class="store-tools-header">常用工具</view>
				<view class="store-tools-list">
					<view class="toolsItem" @click="gotoPath('/pages/storeSide/storeShareInvitation/storeShareInvitation')">
						<view class="images">
							<uni-icons type="personadd-filled" size="28" color="#fff"></uni-icons>
						</view>
						<view class="title">分享邀请</view>
					</view>
					
					<view class="toolsItem" @click="gotoPath('/pages/storeSide/storeInviteLogs/storeInviteLogs')">
						<view class="images">
							<uni-icons type="calendar-filled" size="28" color="#fff"></uni-icons>
						</view>
						<view class="title">邀请记录</view>
					</view>
					
					<view class="toolsItem" @click="scanTheCode" v-if="storeType == '1'">
						<view class="images">
							<uni-icons type="scan" size="28" color="#fff"></uni-icons>
						</view>
						<view class="title">扫码核销</view>
					</view>

					<view class="toolsItem" @click="gotoPath('/pages/storeSide/clerkPerformance/clerkPerformance')"  v-if="storeType == '1'">
						<view class="images">
							<uni-icons type="paperplane-filled" size="28" color="#fff"></uni-icons>
						</view>
						<view class="title">店员业绩</view>
					</view>

					<view class="toolsItem" @click="gotoPath('/pages/storeSide/upCoupon/upCoupon')"  v-if="storeType == '0' || storeType == '1'">
						<view class="images">
							<uni-icons type="vip-filled" size="28" color="#fff"></uni-icons>
						</view>
						<view class="title">发布优惠卷</view>
					</view>

					<view class="toolsItem" @click="gotoPath('/pages/storeSide/shopManagement/shopManagement')">
						<view class="images">
							<uni-icons type="gift" size="28" color="#fff"></uni-icons>
						</view>
						<view class="title">商品管理</view>
					</view>
					
					<view class="toolsItem" @click="gotoPath('/pages/storeSide/disbursementDetail/disbursementDetail')">
						<view class="images">
							<uni-icons type="calendar-filled" size="28" color="#fff"></uni-icons>
						</view>
						<view class="title">收支明细</view>
					</view>
				</view>
			</view>

			<view style="height: 180rpx; width: 100%"></view>
		</view>

		<!-- 背景 -->
		<view class="backdrop"></view>

		<!-- 导航 -->
		<view class="footerTabbar">
			<hwxcStoreTabbar />
		</view>
	</view>
</template>

<script>
import hwxcStoreTabbar from '../../../components/hwxcStoreTabbar/hwxcStoreTabbar.vue';
import { storeSaleBalance,storeselfTake } from '../../../api/payment/index.js';
import { imageUrl, formatAmount } from '../../../utils/tools.js';
export default {
	data() {
		return {
			storeInfo: {},
			userInfo:{},
			balanceInfo: null,
			storeType:""
		};
	},
	components: {
		hwxcStoreTabbar
	},
	async onShow() {
		this.storeInfo = this.$store.state.storeInfo || {};
		this.userInfo = this.$store.state.userInfo || {};

		this.storeType = this.$store.state.storeType;
		this.getstoreSaleBalance();
	},
	methods: {
		gotoPath(path) {
			uni.navigateTo({
				url: path
			});
		},

		// 图片路径拼接
		imageUrls(fileUrl) {
			return imageUrl(fileUrl);
		},

		// 余额信息
		async getstoreSaleBalance() {
			try {
				const resData = await storeSaleBalance({
					type: this.$store.state.storeType
				});
				this.balanceInfo = resData.data;
			} catch (e) {
				throw Error(e);
			}
		},

		// 金额格式
		formatAmounts(num) {
			if (num == '0.00') {
				return '0.00';
			}
			return formatAmount(Number(num));
		},
		
		// 订单销核
		scanTheCode() {
			uni.scanCode({
				onlyFromCamera: true,
				success: async (res)=> {
					const id = res.result;
					
					uni.navigateTo({
						url:`/pages/storeSide/orderEliminate/orderEliminate?id=${id}`
					})
				}
			});
		},
	}
};
</script>

<style>
page {
	display: flex;
	flex-direction: column;
	height: 100%;
}
</style>

<style scoped lang="scss">
.storeHome-main {
	.storeHome-content {
		position: absolute;
		top: 0px;
		left: 0px;
		z-index: 2;
		width: 100%;
		box-sizing: border-box;
		padding: 30rpx;
		.storeInfo {
			display: flex;
			background-color: #2979ff;
			color: #fff;
			.storeInfo-image {
				width: 100rpx;
			}

			.storeInfos {
				flex: 1;
				font-size: 28rpx;
				display: flex;
				justify-content: center;
				flex-direction: column;
				margin-left: 20rpx;

				.storeInfo-title {
					font-size: 30rpx;
					font-weight: bold;
				}

				.storeInfo-zh {
					margin-top: 16rpx;
					.tags {
						margin-left: 10rpx;
					}
				}
			}
		}

		.store-shopWithdraw {
			box-sizing: border-box;
			padding: 30rpx;
			background-color: #fff;
			border-radius: 24rpx;
			margin-top: 32rpx;
			font-size: 28rpx;
			.store-shopWithdraw-header {
			}

			.store-shopWithdraw-midden {
				display: flex;
				align-items: center;
				padding: 30rpx 0px;
				border-bottom: 1px #f3f3f3 solid;
				.money {
					flex: 1;
					font-size: 50rpx;
					font-weight: bold;
				}
				.btn {
					width: 200rpx;
					display: flex;
					align-items: center;
					justify-content: center;
					.btnSty {
						width: 180rpx;
						height: 70rpx;
						line-height: 70rpx;
						font-size: 28rpx;
					}
				}
			}

			.store-shopWithdraw-footer {
				display: flex;
				padding-top: 30rpx;
				.footerItem {
					flex: 1;
					text-align: center;
					.num {
						font-weight: bold;
						margin-bottom: 8rpx;
						font-size: 32rpx;
					}
					.title {
						color: #999;
						font-size: 24rpx;
					}
				}

				.borders {
					border-left: 1px #f3f3f3 solid;
					border-right: 1px #f3f3f3 solid;
				}
			}
		}
	}

	.store-option {
		margin: 32rpx 0px;
		.option-item {
			background-color: #fff;
			height: 140rpx;
			border-radius: 24rpx;
			box-sizing: border-box;
			padding: 20rpx;
			.title {
				font-size: 28rpx;
				font-weight: bold;
				color: #2979ff;
			}
			.des {
				font-size: 24rpx;
				color: #999;
				margin-top: 6rpx;
			}
		}
	}

	.store-tools {
		box-sizing: border-box;
		padding: 30rpx;
		background-color: #fff;
		border-radius: 24rpx;
		.store-tools-header {
			margin-bottom: 30rpx;
			font-weight: bold;
			font-size: 28rpx;
			padding-left: 15rpx;
			border-left: 4px #2979ff solid;
		}

		.store-tools-list {
			display: flex;
			flex-wrap: wrap;
			.toolsItem {
				width: 25%;
				display: flex;
				align-items: center;
				justify-content: center;
				flex-direction: column;
				font-size: 26rpx;
				margin-bottom: 20rpx;
				.images {
					margin-bottom: 6rpx;
					width: 80rpx;
					height: 80rpx;
					border-radius: 50%;
					background-color: #2979ff;
					line-height: 80rpx;
					text-align: center;
				}
			}
		}
	}

	.backdrop {
		background-color: #2979ff;
		height: 260rpx;
		position: absolute;
		top: 0px;
		left: 0px;
		width: 100%;
		z-index: 1;
	}

	.footerTabbar {
		position: absolute;
		bottom: 0px;
		left: 0px;
		width: 100%;
		z-index: 999;
	}
}
</style>
